#include "Thread.h"
#include "BlockQueue.h"
#include <string>
#include <unistd.h>

using namespace BASE;

class Thread1: public Thread{
	public:
		Thread1(){
			queue = new BlockQueue<std::string>("test");
		}

		~Thread1(){
			std::cout << "thread1 stop" << std::endl;
			//queue->stop();
		}

		void put(const std::string & str){
			queue->put(str);
		}

		void thread(){
			std::string str = "test";
			while(isRunning()){
				std::cout << "thread1 get" << std::endl;
				if(queue->get(str)){
					std::cout << str << std::endl;
				}
				std::cout << "thread1 get finished" << std::endl;
			}
		}
	private:
		BlockQueue<std::string> * queue;
};

class Thread2: public Thread{
	public:
		Thread2(Thread1 * _t1):t1(_t1){

		}

		void thread(){
			std::string str = "test";
			while(isRunning()){
				t1->put(str);
				usleep(20000);
			}
		}
	private:
		Thread1 * t1;
};

int main(){
	Thread1 t1;
	Thread2 t2(&t1);
	t1.start();
	t2.start();
	sleep(2);
	return 0;
}
